Object Handling (ODUtils)
This section describes the object-handling utilities defined in the files ODUtils.h and ODUtils.cpp. These utilities are useful for handling OpenDoc objects, especially reference-counted objects.ODDeleteObject
TheODDeleteObject
macro deletes an object, which can be a SOM object or another type of object (such as a C++ object), and sets the variable pointing to it tokODNULL
. This macro takes one parameter, which points to the object, as follows:
ODDeleteObject(object)ODReleaseObject
TheODReleaseObject
macro releases (instead of deleting) a reference-counted SOM object and sets the variable pointing to it tokODNULL
. This macro takes parameters pointing to the SOM environment structure and the object, as follows:
ODReleaseObject(ev, object)ODFinalReleaseObject
TheODFinalReleaseObject
macro is similar toODReleaseObject
, but it is meant to be used to release the last reference to a reference-counted object. It asserts that the object's reference count is equal to 1 before calling itsRelease
method. This macro takes parameters pointing to the SOM environment structure and the object, as follows:
ODFinalReleaseObject(ev, object)ODAcquireObject
TheODAcquireObject
function increments the reference count of an object by 1 unless the object pointer passed into the function iskODNULL
. The prototype of this function appears as follows:
void ODAcquireObject(Environment* ev, ODRefCntObject* object);ODSafeReleaseObject
TheODSafeReleaseObject
function releases a reference-counted object but requires no environment parameter. This function will not throw an exception. It is designed to be used in destructors,CATCH_ALL
exception handling blocks, andsomUninit
methods where no pointer to the environment structure is available. The prototype of this function appears as follows:
void ODSafeReleaseObject(ODRefCntObject* object);ODTransferReference
TheODTransferReference
function decrements one object's reference count while incrementing another object's reference count. It is designed to be used in situations such as when using setter methods where you need to acquire a reference to one object while simultaneously releasing another.This function ensures that the parameters do not point to the same object and that neither is null. It is possible for this function to throw an exception in the unlikely case that the
Acquire
orRelease
method call fails. The prototype of this function appears as follows:
void ODTransferReference( Environment*, ODRefCntObject* oldObj, ODRefCntObject* newObj );ODCopyAndRelease
TheODCopyAndRelease
function returns a pointer to a copy of an object and releases the original object. This function is overloaded: one form takes and returns pointers toODShape
objects; the other takes and returns pointers toODTransform
objects. This function is designed to transfer control of an object to the caller, giving the caller permission to modify the object.If the reference count of the original object is 1, the function is optimized simply to return a pointer to the original object, thereby avoiding the unnecessary expense of copying it. It is possible for this function to throw an exception in the unlikely case that the
GetRefCount
orRelease
method call fails. The prototypes of this function appear as follows:
ODShape* ODCopyAndRelease(Environment* ev, ODShape* shape); ODTransform* ODCopyAndRelease(Environment* ev, ODTransform* transform);ODObjectsAreEqual
TheODObjectsAreEqual
function returnskODTrue
if bothODObject
pointers passed as parameters are not null and point to the same object.
The prototype of the
- IMPORTANT
- Simply comparing the values of the pointers (as in the expression
a==b
) is not sufficient in the presence of distributed objects. Two pointers to the same remote object may have different numeric values.![]()
ODObjectsAreEqual
function appears as follows:
ODBoolean ODObjectsAreEqual(Environment* ev, ODObject* a, ODObject* b);
Main | Page One | What's New | Apple Computer, Inc. | Find It | Contact Us | Help